package com.liu.service.impl;

import com.liu.dao.UserDao;


import com.liu.entity.User;
import com.liu.service.intf.UserService;
import com.liu.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao dao;

    @Override
    public List<User> select(User user) {
        List<User> users=dao.selectByName(user.getUsername());
     return users;

    }

    @Override
    public R del(User user) {
        int i = dao.delete(user);
        if (i>0){
            return new R(200, "删除成功！", null);
        }else {
            return new R(400, "删除失败", null);
        }
    }

    @Override
    public R upda(User user) {
        System.out.println(user);
        int i = dao.update(user);
        if (i > 0) {
            return new R(200, "修改成功！", null);
        } else {
            return new R(400, "修改失败", null);
        }
    }
    @Override
    public R login(User user) {
        List<User> users = select(user);
        System.out.println(users);
        if (users.size() != 0){
            if (users.get(0).getPassword().equals(user.getPassword())){
                return new R(200,"登录成功",null);
            }else{
                return new R(400,"密码错误",null);
            }
        }else {
            return new R(300,"用户名不存在",null);
        }

    }
}
